package com.shaw.client.mvc;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.event.EventType;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.shaw.client.MailServiceAsync;
import com.shaw.client.TestGxt;



public class AppController extends Controller {

  private AppView appView;
  private MailServiceAsync service;

  public AppController() {
	  registerEventTypes(AppEvents.INIT);
		registerEventTypes(AppEvents.LOGIN);

  }

  public void handleEvent(AppEvent event) {
	  EventType type = event.getType();
	    if (type == AppEvents.INIT) {
	      onInit(event);
	    } else if (type == AppEvents.LOGIN) {
	      onLogin(event);
	    } else if (type == AppEvents.Error) {
	      onError(event);
	    }
  }

 
	  protected void onError(AppEvent ae) {
		    System.out.println("error: " + ae.<Object>getData());
		  }


public void initialize() {
    appView = new AppView(this);
  }

 

  private void onInit(AppEvent event) {
    forwardToView(appView, event);
   // service = (MailServiceAsync) Registry.get(TestGxt.SERVICE);
    /*service.getMailFolders("darrell", new AsyncCallback<Folder>() {

		@Override
		public void onFailure(Throwable caught) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void onSuccess(Folder result) {
			// TODO Auto-generated method stub
			
		}
	});*/
  }

  private void onLogin(AppEvent event) {
    forwardToView(appView, event);
  }

}
